package com.hqyj.demo.utils;
import java.util.HashMap;
import java.util.Map;
public class R {

    //状态码
    private  int code;
    //状态信息描述
    private  String message;
    //返回数据
    private final Map<String,Object> data = new HashMap<> ();

    private static  R r;

    public static R ok() {
        r = new R ();
        r.code = HttpStatus.SUCCESS;
        return r;
    }

    public static R error() {
        r = new R ();
        r.code = HttpStatus.ERROR;
        return r;
    }

    public static R error(int code) {
        r = new R ();
        r.code = code;
        return r;
    }

    public R message(String describe) {
        r.message =describe;
        return r;
    }

    public R data(String key,Object value) {
        r.data.put (key,value);
        return r;
    }

    @Override
    public String toString() {
        return "R{" +
                "code=" + code +
                ", message='" + message + '\'' +
                ", data=" + data +
                '}';
    }

    public R() {
    }

    public int getCode() {
        return code;
    }

    public String getMessage() {
        return message;
    }

    public Map<String, Object> getData() {
        return data;
    }
}
